<template>

  <el-container>
    <!-- 头部导航 -->
    <el-header>
      <div>
        <img src="../assets/logo.png" alt="">
        <span>电商后台管理系统</span>
      </div>
      <el-button type="info" round @click="logout">退出登录</el-button>
    </el-header>
    <el-container>
      <el-aside width="200px">

        <!-- 左侧导航栏 -->
        <el-menu default-active="2"
          class="el-menu-vertical-demo"
          background-color="#545c64"
          text-color="#fff"
          unique-opened
          active-text-color="#409EFF"
          router>
          <!-- 一级菜单 -->
          <el-submenu :index="item.id+''" v-for="item in menuList" :key="item.id">
            <template slot="title">
              <i :class="iconsObj[item.id]"></i>
              <span>{{item.authName}}</span>
            </template>
            
            <!-- 二级菜单 -->

            <el-menu-item
             :index="'/' + subItem.path"
             v-for="subItem in item.children"
             :key="subItem.id" >
              <template slot="title">
                <!-- 图标 -->
                <i class="el-icon-menu"></i>
                <!-- 文本 -->
                <span>{{subItem.authName}}</span>
              </template>
            </el-menu-item>

          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
  export default {
    data() {
      return {
        menuList: [],
        iconsObj: {
          '125': 'iconfont icon-user',
          '103': 'iconfont icon-tijikongjian',
          '101': 'iconfont icon-shangpin',
          '102': 'iconfont icon-danju',
          '145': 'iconfont icon-baobiao'
        }
      }
    },
    created() {
      this.getMenuList()
    },
    methods: {
      logout() {
        window.sessionStorage.clear();
        this.$router.push('/login');
        window.console.clear()
      },
      async getMenuList() {
        const {
          data: res
        } = await this.$http.get('menus')
        if (res.meta.status !== 200) return this.$message.error(res.meta.msg)
        this.menuList = res.data
        


      }
    }
  }
</script>

<style lang="less" scoped>
  .el-header {
    display: flex;
    background-color: #484d57;
    font-size: 22px;
    justify-content: space-between;
    align-items: center;

    >div>img {
      height: 60px;
      width: 60px;
    }

    >div {
      // text-align: center;
      display: flex;
      align-items: center;

      span {
        margin-left: 18px;
      }
    }
  }

  .el-aside {
    background-color: #545c64;
    .el-menu {
        border-right: none;
      }
  }

  /* .el-main{
    background-color: #909399;
  } */
  .el-container {
    height: 100%;
  }

  .iconfont {
    margin-right: 10px;
  }
</style>
